package com.sync.data.ievent.entity;

import com.sync.data.base.BaseEntity;
import com.sync.data.common.annotation.FieldProps;
import com.sync.data.common.annotation.FieldType;
import com.sync.data.common.annotation.RenderType;
import com.sync.data.common.obj.annoation.ObjectPrefix;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.Entity;
import java.io.Serializable;
import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.List;

/**
 * 客户对象
 *
 * @author liquanchang
 */
@Getter
@Setter
@Entity
@DiscriminatorValue("personal")
@ObjectPrefix("bhcp")
public class Hcp extends BaseAccount implements Serializable {

    private static final long serialVersionUID = 1L;

    //=======================================

    @FieldProps(type = FieldType.STRING, label = "客户名")
    public String name;

    /**
     * 客户名称(中文)
     */
    @FieldProps(type = FieldType.STRING, label = "客户名称")
    private String accName;
    /**
     * 客户类别
     */
    @FieldProps(type = FieldType.STRING, label = "客户记录类型")
    private String accType;
    /**
     * 客户类别
     */
    @FieldProps(type = FieldType.STRING, label = "客户类别")
    @Column(insertable = false,updatable = false)
    private String accCategory;
    /**
     * 客户名称(英文)
     */
    @FieldProps(type = FieldType.STRING, label = "客户名称(英文)")
    private String accNameEn;
    /**
     * 职称
     */
    @FieldProps(type = FieldType.STRING, label = "主要专业")
    private String accTitle;

    /**
     * 和 accTitle 取同样的值
     */
    @FieldProps(type = FieldType.STRING, label = "职称")
    @Transient
    private String jobTitle;
    /**
     * 标准科室
     */
    @FieldProps(type = FieldType.STRING, label = "部门")
    private String accDepart;

    /**
     * 医院名称
     */
    @FieldProps(type = FieldType.STRING, label = "机构")
    private String hospitalName;

    /**
     * 国家
     */
    @FieldProps(type = FieldType.STRING, label = "国家/地区")
    private String accCountry;
    /**
     * 客户地址
     */
    @FieldProps(type = FieldType.STRING, label = "地址")
    private String accAddress;
    /**
     * 省
     */
    @FieldProps(type = FieldType.CASCADE,label = "省)",renderType = RenderType.Cascader,cascadeLevel = 1,cascadeObject = "accAddress",notNull = false)
    private String accProvince;

    /**
     * 市
     */
    @FieldProps(type = FieldType.CASCADE,label = "市)",renderType = RenderType.Cascader,cascadeLevel = 2,cascadeObject = "accAddress",notNull = false)
    private String accCity;

    /**
     * 区
     */
    @FieldProps(type = FieldType.STRING, label = "区")
    private String accRegion;
    /**
     * 原始数据来源
     */
    @FieldProps(type = FieldType.STRING, label = "原始数据来源")
    private String dataFrom;
    /**
     * 原始数据ID
     */
    @FieldProps(type = FieldType.STRING, label = "原始数据ID")
    private String legacyId;
    /**
     * 原始数据父级ID
     */
    @FieldProps(type = FieldType.STRING, label = "原始数据父级ID")
    private String legacyPid;

    @FieldProps(type = FieldType.STRING, label = "电话")
    private String accPhone;

    /**
     * 是否是目标
     */
    @FieldProps(type = FieldType.NUMBER, label = "是否是目标")
    private Integer isTarget;

    @FieldProps(type = FieldType.NUMBER, label = "是否验证")
    private Integer verified;

    /**
     * 外部编号
     */
    @FieldProps(type = FieldType.STRING, label = "外部编号")
    private String externalId;

    /**
     * 是否生效 0-无效, 1-有效 2-临时(用于non-hcp场景)
     */
    @FieldProps(type = FieldType.DICT, label = "客户状态")
    private Integer isActive;


    private String customField1;
    private String customField2;
    private String customField3;
    private String customField4;
    private String customField5;
    private String customField6;
    private String customField7;
    private String customField8;
    private String customField9;
    private String customField10;


    //====================================



    @FieldProps(type = FieldType.STRING, label = "HCP Code", readOnly = true)
    private String accCode;

    /**
     * 级别
     */
    @FieldProps(type = FieldType.STRING, label = "级别")
    private String accLevel;
    /**
     * 层级(KOL等级)
     */
    @FieldProps(type = FieldType.STRING, label = "层级")
    private String accTier;

    /**
     * 文凭
     */
    @FieldProps(type = FieldType.STRING, label = "文凭")
    private String accPriCredential;
    /**
     * 专业资格
     */
    @FieldProps(type = FieldType.STRING, label = "专业资格")
    private String accProfDesig;

    /**
     *
     */
    @FieldProps(type = FieldType.STRING, label = "邮寄地址")
    private String accShipAddr;

    @FieldProps(type = FieldType.STRING, label = "性别")
    private String accGender;

    @FieldProps(type = FieldType.STRING, label = "电子邮箱")
    private String accPersonEmail;

    @FieldProps(type = FieldType.STRING, label = "备注")
    private String remark;


    /**
     * 挂牌科室
     */
    @FieldProps(type = FieldType.STRING, label = "挂牌科室")
    private String primaryParentName;

    /**
     * 医生执照号码
     */
    @FieldProps(type = FieldType.STRING, label = "医生执照号码")
    private String physiciansLicenseNumber;

    /**
     * email2
     */
    @FieldProps(type = FieldType.STRING, label = "email2")
    private String email2;

    /**
     * 禁止远程会议
     */
    @FieldProps(type = FieldType.STRING, label = "禁止远程会议")
    private Integer noRemoteInteraction;

    /**
     * 拜访偏好
     */
    @FieldProps(type = FieldType.STRING, label = "拜访偏好")
    private String doNotCall;

    /**
     * 是否必须预约
     */
    @FieldProps(type = FieldType.STRING, label = "是否必须预约")
    private String isAppointmentRequired;

    /**
     * CLM拜访
     */
    @FieldProps(type = FieldType.STRING, label = "CLM拜访")
    private String clmVisit;

    /**
     * 远程CLM拜访
     */
    @FieldProps(type = FieldType.STRING, label = "远程CLM拜访")
    private String remoteClmVisit;


    /**
     * 面对面拜访
     */
    @FieldProps(type = FieldType.STRING, label = "面对面拜访")
    private String faceToFaceVisit;

    /**
     * 发送简报/消息
     */
    @FieldProps(type = FieldType.STRING, label = "发送简报/消息")
    private String sendMessage;

    /**
     * 合规邮件
     */
    @FieldProps(type = FieldType.STRING, label = "合规邮件")
    private String complianceEmail;

    /**
     * 线上会议
     */
    @FieldProps(type = FieldType.STRING, label = "线上会议")
    private String onlineMeeting;

    /**
     * 合同拒绝
     */
    @FieldProps(type = FieldType.STRING, label = "合同拒绝")
    private String consentRejected;

    /**
     * 电话联络
     */
    @FieldProps(type = FieldType.STRING, label = "电话")
    private String telephoneContact;

    /**
     * Crystal知情同意书签署日期
     */
    @FieldProps(type = FieldType.DATE, label = "Crystal知情同意书签署日期", renderType = RenderType.DatePicker)
    private Date crystalSignedDate;

    /**
     * 技术职称(职务)
     */
    @FieldProps(type = FieldType.STRING, label = "技术职称(职务)")
    private String techTitle;

    @FieldProps(type = FieldType.STRING, label = "是否讲者")
    private Integer isSpeaker;

    /**
     * 微信openId
     */
    @FieldProps(type = FieldType.STRING, label = "openId")
    private String openId;

    /**
     * 微信unionId
     */
    @FieldProps(type = FieldType.STRING, label = "微信unionId")
    private String unionId;

    /**
     * 是否实名
     */
    @FieldProps(type = FieldType.STRING, label = "是否实名")
    private Integer isRealName;

    /**
     * 拒绝签署知情同意书
     */
    @FieldProps(type = FieldType.NUMBER, label = "拒绝签署知情同意书", renderType = RenderType.Switch)
    private Integer refuseSignCrystal;


    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "accId", referencedColumnName = "id",insertable = false,updatable = false)
    @NotFound(action = NotFoundAction.IGNORE)
    private List<MtSpeakerSchema> speakerSchemas;

    @FieldProps(type = FieldType.STRING, label = "所属部门")
    private String sysOrgCode;

    @FieldProps(type = FieldType.STRING, label = "客户简称")
    private String accNameAbbr;

    @FieldProps(type = FieldType.STRING, label = "国籍")
    private String accNationality;

    @FieldProps(type = FieldType.STRING, label = "主要专长领域")
    private String accPriSpecialty;

    @FieldProps(type = FieldType.STRING, label = "第二专长领域")
    private String accSecondSpecialty;

    @FieldProps(type = FieldType.STRING, label = "商务邮箱")
    private String accBizEmail;


    @FieldProps(type = FieldType.STRING, label = "手机")
    private String accMobile;

    @FieldProps(type = FieldType.STRING, label = "传真")
    private String accFax;

    @FieldProps(type = FieldType.STRING, label = "微信号ID")
    private String accWechatId;

    @FieldProps(type = FieldType.STRING, label = "证件类型")
    private String accIdType;

    /**
     * 证件号码
     */
    @FieldProps(type = FieldType.STRING, label = "证件号码")
    private String accIdNum;

    /**
     * 值和accIdNum一样, 为了页面显示用
     */
    @Transient
    @FieldProps(type = FieldType.STRING, label = "身份证号")
    private String accIdentityNum;

    @FieldProps(type = FieldType.DATE, label = "证件过期日期")
    private Date accIdExipreDate;

    @FieldProps(type = FieldType.STRING, label = "银行名称")
    private String accBankName;

    @FieldProps(type = FieldType.STRING, label = "银行账户")
    private String accBankAccount;

    @FieldProps(type = FieldType.STRING, label = "发票地址")
    private String accBillAddr;

    @FieldProps(type = FieldType.STRING, label = "主要地址")
    private String accPriAddr;

    @FieldProps(type = FieldType.STRING, label = "OneKey ID")
    private String onekeyId;

    @FieldProps(type = FieldType.STRING, label = "医院Code")
    private String hcoCode;

    @FieldProps(type = FieldType.STRING, label = "医院")
    private String hcoName;

    @FieldProps(type = FieldType.STRING, label = "master模式业务外键")
    private String masterDataId;

    @FieldProps(type = FieldType.STRING, label = "尽职调查信息备注")
    private String responsibleRemark;

    @FieldProps(type = FieldType.STRING, label = "学术头衔")
    private String academicTitle;

    @FieldProps(type = FieldType.STRING, label = "职位类型")
    private String positionType;

    @FieldProps(type = FieldType.STRING, label = "医院等级")
    private String hospitalGrade;

    @FieldProps(type = FieldType.STRING, label = "医院类型")
    private String hcoType;

    @FieldProps(type = FieldType.STRING, label = "机构类型")
    private String organizationType;

    @FieldProps(type = FieldType.NUMBER, label = "是否展示")
    private Integer isShow;

    @FieldProps(type = FieldType.STRING, label = "邀请码")
    private String invitationCode;


    @FieldProps(type = FieldType.STRING, label = "英文地址")
    private String accEnAddress;

    @FieldProps(type = FieldType.STRING, label = "Bank Key")
    private String bankId;

    @FieldProps(type = FieldType.STRING, label = "公司代码")
    private String companyCode;

    @FieldProps(type = FieldType.STRING, label = "联系人姓名")
    private String contactName;

    @FieldProps(type = FieldType.STRING, label = "联系人职位")
    private String contactPosition;

    @FieldProps(type = FieldType.STRING, label = "联系人电话")
    private String contactPhone;

    @FieldProps(type = FieldType.STRING, label = "联系人邮箱")
    private String contactEmail;

    @FieldProps(type = FieldType.STRING, label = "预估未来12个月的费用")
    private String expense;

    @FieldProps(type = FieldType.STRING, label = "尽职调查有效期")
    private String responsibleTime;

    @FieldProps(type = FieldType.STRING, label = "纳税人识别号")
    private String taxPayerId;


    @Transient
    @FieldProps(type = FieldType.STRING, label = "证件类型")
    private String speakerIdType;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "身份证号")
    private String speakerIdNum;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "身份证号后4位")
    private String speakerIdNumPost4Num;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "银行名称")
    private String speakerBankName;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "供应商编号")
    private String speakerVendorCode;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "Speaker Library")
    private String speakerBankSpeakerLibrary;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "Speaker Status")
    private String speakerBankSpeakerStatus;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "银行合作类型")
    private String speakerBankPartnerType;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "TA领域")
    private String speakerTaRegion;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "锁定原因")
    private String speakerLockReason;

    @Transient
    @FieldProps(type = FieldType.DATE, label = "讲者最后使用时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm")
    private Date speakerLastUsedTime;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "讲者标签")
    private String speakerTag;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "锁定标签")
    private String speakerLockTag;

    @Transient
    @FieldProps(type = FieldType.DATE, label = "最后使用时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date migrationLastUseDate;

    @FieldProps(type = FieldType.STRING, label = "实名描述")
    private String realNameDescription;

    @FieldProps(type = FieldType.DICT, label = "是否利益冲突code")
    private Integer isInterestConflict;


    @FieldProps(type = FieldType.DICT, label = "HCP类型code")
    private Integer hcpType;


    public String getSpeakerTag() {
        if(null != isSpeaker && isSpeaker.intValue()  == 1){
            return "专家";
        }else {
            return null;
        }
    }

    public String getSpeakerLockTag() {
        if (speakerSchemas==null||speakerSchemas.isEmpty()) {
            return null;
        }
        return null;
    }
}
